﻿Global.namespace("System.Core.Handler");
System.Core.Handler.HtmlLogWriter=function(config){
    try{
        if(Config.runningMode === System.Core.Enum.RunningMode.debug){
            this.id="logScreen"+Global.random();
            var html = StringHandler.format(
                "<div id='{0}' class='LogPanel' />",
                this.id
            );
            $(html).appendTo($('body'));
            this.output=$('#'+this.id);
            this.createHeader();
        }
        System.Core.Handler.HtmlLogWriter.superclass.constructor.call(this,config);
    }catch(e){
        alert(e.message);
    }
};
Global.extend(System.Core.Handler.HtmlLogWriter, System.Core.Handler.LogWriter,{
    createHeader:function(){
        var ctr=this;
        var html="<img id='{1}' src='{0}expand.png' class='ImgIcon'/>";
        html=StringHandler.format(
            html,
            Config.imageUrl,
            this.id+'_ImgIcon'
        );
        $(html).appendTo(this.output);
        
        $('#'+ this.id+'_ImgIcon').click(function(){
            
            var item=$('#'+this.id);
            var collapse=item.attr('collapse');
            
            if(collapse==='1'){
                item.attr('src',Config.imageUrl+'expand.png');
                item.attr('collapse',0);
                ctr.expand();
                return;
            }
            item.attr('src',Config.imageUrl+'collapse.png');
            item.attr('collapse',1);
            ctr.collapse();
        });
    },
    collapse:function(){
        this.output.animate({height:15},2000);
    },
    expand:function(){
        this.output.animate({height:'100%'},2000);
    },
    write:function(type,message){
        // do nothing if not in debug mode
        if(Config.runningMode!==System.Core.Enum.RunningMode.debug){ return;}
        
        var html=StringHandler.format(
            "<div class='{0}'>{1}</div>",
            type,
            message
        );
        $(html).appendTo(this.output);
    }
});
